package com.example.service;

import com.example.entity.EmployeeDetail;
import com.example.exception.CustomException;
import com.example.mapper.EmployeeDetailMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 员工详情服务类
 */
@Service
public class EmployeeDetailService {

    @Resource
    private EmployeeDetailMapper employeeDetailMapper;

    /**
     * 新增
     */
    public void add(EmployeeDetail employeeDetail) {
        // 检查是否已存在该员工的详情信息
        EmployeeDetail existDetail = employeeDetailMapper.selectByEmployeeId(employeeDetail.getEmployeeId());
        if (existDetail != null) {
            throw new CustomException("400", "该员工已有详情信息，请勿重复添加");
        }
        employeeDetailMapper.insert(employeeDetail);
    }

    /**
     * 删除
     */
    public void deleteById(Integer id) {
        employeeDetailMapper.deleteById(id);
    }
    
    /**
     * 根据员工ID删除
     */
    public void deleteByEmployeeId(Integer employeeId) {
        employeeDetailMapper.deleteByEmployeeId(employeeId);
    }

    /**
     * 批量删除
     */
    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            employeeDetailMapper.deleteById(id);
        }
    }

    /**
     * 修改
     */
    public void updateById(EmployeeDetail employeeDetail) {
        employeeDetailMapper.updateById(employeeDetail);
    }

    /**
     * 根据ID查询
     */
    public EmployeeDetail selectById(Integer id) {
        return employeeDetailMapper.selectById(id);
    }
    
    /**
     * 根据员工ID查询
     */
    public EmployeeDetail selectByEmployeeId(Integer employeeId) {
        return employeeDetailMapper.selectByEmployeeId(employeeId);
    }

    /**
     * 查询全部
     */
    public List<EmployeeDetail> selectAll(EmployeeDetail employeeDetail) {
        return employeeDetailMapper.selectAll(employeeDetail);
    }
}